import 'package:flutter/material.dart';
import '../model/post.dart';

void main() => runApp(App());

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
      theme: ThemeData(
          //设置 顶部主题颜色
          primarySwatch: Colors.yellow),
    );
  }
}

/**
 * 首页
 */
class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    // listView 的item
    Widget _listItemBuilder(BuildContext context, int index) {
      return Container(
        color: Colors.amber, //背景颜色
        margin: EdgeInsets.all(8.0), //间距
        child: Column(
          children: <Widget>[
            Image.network(posts[index].imageUrl), //显示图片地址
            SizedBox(
              height: 16.0,
            ), //距离底部距离
            Text(
              posts[index].title,
              style: Theme.of(context).textTheme.title, //标题
            ),
            Text(
              posts[index].title,
              style: Theme.of(context).textTheme.subhead, //小标题
            ),
            SizedBox(
              height: 16.0,
            ),
          ],
        ),
      );
    }

    return Scaffold(
      backgroundColor: Colors.grey[100],
      appBar: AppBar(
          //导航条
          title: Text('aaa')),
      body: ListView.builder(
        itemCount: posts.length,
        itemBuilder: _listItemBuilder,
      ), //主体内容区
    );
  }
}

class Hello extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(
        'Hello',
        textDirection: TextDirection.ltr,
        style: TextStyle(
            fontSize: 40.0, fontWeight: FontWeight.bold, color: Colors.yellow),
      ),
    );
  }
}
